Skip to content

Clean up temporary files created for Windows background processes#300

Merged
swissspidy merged 6 commits intotry/osfrom
copilot/sub-pr-274
Feb 5, 2026
Merged

Clean up temporary files created for Windows background processes#300
swissspidy merged 6 commits intotry/osfrom
copilot/sub-pr-274

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

The background_proc() method creates temporary files for stdout/stderr on Windows but never deletes them, leaving orphaned files on the filesystem.

Changes:

  • Track temp files: Added $temp_files property to store file paths for cleanup
  • Clean on error: Delete temp files immediately when process fails to start
  • Clean on success: Delete temp files in AfterScenario hook when process terminates
  • Helper method: Extracted cleanup_temp_files() to handle safe deletion with existence checks

Implementation:

// Create and track temp files
$stdout_file = tempnam( sys_get_temp_dir(), 'behat-stdout-' );
$stderr_file = tempnam( sys_get_temp_dir(), 'behat-stderr-' );
// ...
$this->temp_files[] = $stdout_file;
$this->temp_files[] = $stderr_file;

// Cleanup helper with existence check
private function cleanup_temp_files( ...$files ): void {
    foreach ( $files as $file ) {
        if ( file_exists( $file ) ) {
            unlink( $file );
        }
    }
}

Temp files now cleaned up regardless of process success/failure.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 5, 2026 17:40
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on improving compatibility with other operating systems Clean up temporary files created for Windows background processes Feb 5, 2026
Copilot AI requested a review from swissspidy February 5, 2026 17:46
@swissspidy swissspidy marked this pull request as ready for review February 5, 2026 18:23
@swissspidy swissspidy requested a review from a team as a code owner February 5, 2026 18:23
Copilot AI review requested due to automatic review settings February 5, 2026 18:23
@swissspidy swissspidy merged commit 2aed0b8 into try/os Feb 5, 2026
2 checks passed
@swissspidy swissspidy deleted the copilot/sub-pr-274 branch February 5, 2026 18:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a resource leak where temporary files created for background processes on Windows were never cleaned up. The implementation adds proper tracking and cleanup of these temporary files both on process failure and at scenario completion.

Changes:

  • Added $temp_files property to track temporary file paths for cleanup
  • Implemented cleanup logic in afterScenario hook after process termination
  • Added immediate cleanup when background process fails to start on Windows

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants